<?php
include 'config.php';
 include('./class/class.database.php');
  $db = new database($server, $username, $password, $database);
  $db->connect(database);
$user = strip_tags(trim($_REQUEST['username']));

if(strlen($user) <= 0)
{
  echo json_encode(array('code'  =>  -1,
  'result'  =>  'Invalid username, please try again.'
  ));
  die;
}

// Query database to check if the username is available
$query = "SELECT * FROM users WHERE user_name = '$user' LIMIT 1";
// Execute the above query using your own script and if it return you the
// result (row) we should return negative, else a success message.
 
$result = mysql_query($query);
$available = mysql_num_rows($result);
 
if($available)
{
  echo json_encode(array('code'  =>  0,
  'result'  =>  " Sorry but username <b>$user</b>  is already taken."
  ));
  die;
}
else
{
  echo  json_encode(array('code'  =>  1,
  'result'  =>  " Username <b>$user</b> is available"
  ));
  die;
}
die;
?>